package com.yunxin.admin.system.infra.framework.security;

import com.yunxin.admin.system.infra.framework.security.userdetails.UserDetailsExternalService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 支持多种方式认证
 *
 * @author zero°
 * @since 2023-11-25
 */
@RequiredArgsConstructor
public class GlobalAuthenticationConfigurer extends GlobalAuthenticationConfigurerAdapter {

    private final SmsAuthenticationProvider smsAuthenticationProvider;

    private final UserDetailsExternalService userDetailsExternalService;

    private final PasswordEncoder passwordEncoder;

    @Override
    public void init(AuthenticationManagerBuilder builder) throws Exception {
        builder.userDetailsService(userDetailsExternalService).passwordEncoder(passwordEncoder);
        builder.authenticationProvider(smsAuthenticationProvider);
    }
}
